package com.sunbim.rsrv.pojo;

import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.sunbim.rsrv.pojo.typeHandler.RockyAuxiliaryJsonTypeHandler;
import com.sunbim.rsrv.pojo.typeHandler.RockyBodyJsonTypeHandler;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.time.LocalDateTime;

@Data
@TableName("risk_rocky")
@ApiModel(value = "RiskRocky对象", description = "石头文物风险")
public class RiskRocky implements Serializable {
    private static final long serialVersionUID = 1L;

    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @ApiModelProperty("所属用户id")
    @TableField("user_id")
    @JsonProperty("user_id")
    private Integer userId;

    @ApiModelProperty("所属文物id")
    @TableField("relics_id")
    @JsonProperty("relics_id")
    private Integer relicsId;

    @ApiModelProperty("本体劣化和结构安全风险")
    @TableField(value = "body", typeHandler = RockyBodyJsonTypeHandler.class)
    private RiskRocky.Body body;

    @ApiModelProperty("附属建筑安全风险")
    @TableField(value = "auxiliary", typeHandler = RockyAuxiliaryJsonTypeHandler.class)
    private RiskRocky.Auxiliary auxiliary;

    @ApiModelProperty("主要问题")
    @TableField("problem")
    private String problem;

    @ApiModelProperty("总分")
    @TableField("total_score")
    private Integer totalScore = 0;

    @TableField(value = "create_time", fill = FieldFill.INSERT)
    @JsonProperty(value = "create_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createTime;

    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    @JsonProperty(value = "update_time")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateTime;

    public RiskRocky(Integer userId, Integer relicsId) {
        this.userId = userId;
        this.relicsId = relicsId;
    }


    public RiskRocky() {
    }

    @Data
    public static class Body {
        @ApiModelProperty("表面污染")
        @NotNull(message = "表面污染风险分数不能为空")
        private Integer contaminate = 0;

        @ApiModelProperty("表面分化程度")
        @NotNull(message = "表面分化程度风险分数不能为空")
        private Integer weathering = 0;

        @ApiModelProperty("历次修缮部位及其他")
        @NotNull(message = "其他风险分数不能为空")
        private Integer other = 0;

        @ApiModelProperty("结构失衡")
        @NotNull(message = "结构失衡风险分数不能为空")
        private Integer buckling = 0;

        @ApiModelProperty("风险等级")
        @TableField(exist = false)
        private Integer level = 0;

        @ApiModelProperty("总分")
        private Integer score = 0;

        public Body() {
        }
    }

    @Data
    public static class Auxiliary {

        @ApiModelProperty("表面劣化")
        @NotNull(message = "表面劣化风险分数不能为空")
        private Integer cracking = 0;

        @ApiModelProperty("结构安全")
        @NotNull(message = "表面劣化风险分数不能为空")
        private Integer structure = 0;

        @ApiModelProperty("总分")
        @TableField("score")
        private Integer score = 0;

        @ApiModelProperty("风险等级")
        @TableField(exist = false)
        private Integer level = 0;

        public Auxiliary() {
        }
    }
}
